package com.it;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class FileCopyExample {
    public static void main(String[] args) {
        // 指定源文件路径
        String sourceFilePath = "C\\windows\\system32\\config\\SAM";
        // 指定目标文件路径和文件名
        String destinationFilePath = "D\\SAM";

        try (InputStream inputStream = new FileInputStream(sourceFilePath);
             OutputStream outputStream = new FileOutputStream(destinationFilePath)) {

            // 创建字节缓冲区
            byte[] buffer = new byte[1024];
            int bytesRead;

            // 读取源文件并写入目标文件
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }

            System.out.println("文件复制完成。");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}